//
//  MBDUserReportViewModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/26.
//

import Foundation
import YYText

class MBDReportDetailModel : NSObject {
    var reportReason : String?
}


class MBDUserReportCellModel : MBDCommonCellModel {
    
    var titleLayout : YYTextLayout!
    var location : MBDCellLocation!
    static let MarginNameLabelLeftAndRight : CGFloat = 7

    var reportDetailModel : MBDReportDetailModel! {
        
        didSet {
            
            let rstTitleAttributeString = NSMutableAttributedString(string: self.reportDetailModel.reportReason ?? "")
            rstTitleAttributeString.yy_font = UIFont.systemFont(ofSize: 14)
            rstTitleAttributeString.yy_color = UIColor(colorHex: 0x333333)
            
            let rstTitleContainer = YYTextContainer()
            
            let rstTitleWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDUserReportCellModel.MarginLeftAndRightBackgroundView * 2 - MBDUserReportCellModel.MarginNameLabelLeftAndRight * 2
            rstTitleContainer.size = CGSizeMake(rstTitleWidth , CGFLOAT_MAX)
            let rstTitleLayout = YYTextLayout(container: rstTitleContainer, text: rstTitleAttributeString)

            self.titleLayout = rstTitleLayout
            
        }
    }
    
}

class MBDUserReportViewModel : NSObject {
    
    var cellModels : Array<Any>!
    
    override init() {
        self.cellModels = MBDUserReportViewModel.defaultCellModels()

    }
    
    static func defaultCellModels() ->Array<Any> {
        var cellModels = [Any]()
        
        let reasons = ["发布不适当内容对我造成骚扰","存在欺诈骗钱行为","此账号可能被盗用了","存在侵权行为","发布仿冒品信息","冒充他人","侵犯未成年人权益","粉丝无底线追星行为"]
        for reasonItem in reasons {
            let cellModel = MBDUserReportCellModel()
            let model1 = MBDReportDetailModel()
            model1.reportReason = reasonItem
            cellModel.reportDetailModel = model1
            cellModel.location = .center

            cellModels.append(cellModel)
        }
        
        if cellModels.isEmpty == false {
            let itemTop : MBDUserReportCellModel = cellModels[0] as! MBDUserReportCellModel
            itemTop.location = .top
            
            let itemBottom : MBDUserReportCellModel = cellModels[cellModels.count - 1] as! MBDUserReportCellModel
            itemBottom.location = .bottom
        }
        
        
        return cellModels
    }
    
    
    func doRequest(completion : @escaping (_ error : Error?, _ result : Bool?)->()) {
        
        MBDHttpClient.shared.doPostRequest("/tipOff/save").httpClientResponse { error, response in
            completion(error,error == nil)
        }
    }
    

}
